<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="vue.global.js"></script>
</head>
<body>
<div id = 'app'>
    <!--    watch n1,n2的变化会触发n3的计算-->
    {{n1}} * {{n2}} = {{n3}}
</div>
<script>
    const app = Vue.createApp({
        data() {
            return {
                n1:3,
                n2:4,
                n3:12
            }
        },
        watch:{
            n3(newValue, oldValue){
                let ret = [];
                for(let i =0;i<=newValue;i++){
                    if(newValue % i === 0){
                        ret.push([i , newValue/i]);
                    }
                }
                let now = ret[ Math.floor( Math.random()*ret.length )]
                this.n1 = now[0];
                this.n2 = now[1];
            }
        }

    });
    let vm = app.mount('#app');

    //n3的修改影响了n1，n2
    setTimeout(()=>{
        vm.n3 = 3;
    },2000)


</script>
</body>
</html>